package xin.yangshuai.juc01.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * HelloController
 *
 * @author shuai
 * @date 2022/2/11
 */
@RestController
public class HelloController {

    private List<String> list = new CopyOnWriteArrayList<>();
    private Set<String> set = new CopyOnWriteArraySet<>();

    private Map<String, String> map = new ConcurrentHashMap<>();

    @RequestMapping("clean")
    public String clean() {
        list = new CopyOnWriteArrayList<>();
        set = new CopyOnWriteArraySet<>();
        map = new ConcurrentHashMap<>();
        return "clean";
    }

    @RequestMapping("list")
    public String list() {

        CopyOnWriteArrayList<Object> objects = new CopyOnWriteArrayList<>();
        objects.add("s");


        list.add(UUID.randomUUID().toString().substring(0, 4));
        System.out.println(list);
        return "list";
    }

    @RequestMapping("set")
    public String set() {
        set.add(UUID.randomUUID().toString().substring(0, 4));
        System.out.println(set);
        return "set";
    }

    @RequestMapping("map")
    public String map() {
        String s = UUID.randomUUID().toString().substring(0, 4);
        map.put(s, s);
        System.out.println(map);
        return "map";
    }
}
